import 'dart:convert';

import 'package:enterprise_v6_app/app/data/common/choice_bean.dart';
import 'package:enterprise_v6_app/generated/json/base/json_field.dart';
import 'package:enterprise_v6_app/generated/json/hazard_archive_tree_entity.g.dart';

export 'package:enterprise_v6_app/generated/json/hazard_archive_tree_entity.g.dart';

@JsonSerializable()
class HazardArchiveTreeEntity extends ChoiceBean {
  HazardArchiveTreeEntity();

  factory HazardArchiveTreeEntity.fromJson(Map<String, dynamic> json) => $HazardArchiveTreeEntityFromJson(json);

  late List<HazardArchiveTreeEntity> children = [];
  late String companyCode = '';
  late String createBy = '';
  late String createById = '';
  late String createDate = '';
  late String deleted = '';
  late String id = '';
  late String name = '';
  late String pid = '';
  late String updateBy = '';
  late String updateById = '';
  late String updateDate = '';

  bool _isChecked = false;

  Map<String, dynamic> toJson() => $HazardArchiveTreeEntityToJson(this);

  @override
  String toString() {
    return jsonEncode(this);
  }

  @override
  String getId() => id;

  @override
  bool getIsChecked() => _isChecked;

  @override
  String getShowName() => name;

  @override
  setIsChecked(bool isChecked) {
    _isChecked = isChecked;
  }

  List<HazardArchiveTreeEntity> get allChildren {
    final List<HazardArchiveTreeEntity> list = [];
    for (final HazardArchiveTreeEntity item in children) {
      list.add(item);
      list.addAll(item.allChildren);
    }
    return list;
  }
}
